package com.zj;

import com.zj.common.BuilderParam;
import com.zj.common.TiripPackage;
import com.zj.common.mq.SendMessage;
import com.zj.common.mq.SsReciveMessage;
import com.zj.common.xml.XmlUtil;
import com.zj.request.*;
import com.zj.request.body.*;
import com.zj.request.head.*;
import com.zj.response.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.jms.BytesMessage;
import javax.jms.Message;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * @createUser daiyuan
 * @createTime 2019/3/5 15:46
 * @describe TODO
 **/

@RunWith(SpringRunner.class)
@SpringBootTest
public class Request {

    private static final Logger logger = LoggerFactory.getLogger(Request.class);
    @Autowired
    SendMessage sendMessage;

    @Autowired
    SsReciveMessage ssReciveMessage;


    /**
     * @throws Exception
     * @createUser daiyuan
     * @createTime 2019/2/27 10:20 AM
     * @describe 个人银行缴费参保查询
     **/

    @Test
    public void gryhJfCb() throws Exception {
        JhSyYhCbcxRqBody open = new JhSyYhCbcxRqBody();
        JhSyYhcxjfTyReqHead head = new JhSyYhcxjfTyReqHead("20190305");
        open.setHead(head);

        JhSyYhCbcxReqBody jhSyYhCbcxReqBody = new com.zj.request.body.JhSyYhCbcxReqBody("201", "430111196402120016",
                "胡迪强");
        open.setBody(jhSyYhCbcxReqBody);
        String str = BuilderParam.getJhSyYhcxjfTy(open);
        System.out.println(str);
        String messageId = sendMessage.sendSs(UUID.randomUUID().toString(), str);
        Message message = ssReciveMessage.reciveFromCorrelationID(messageId);
        BytesMessage msg = (BytesMessage) message;

        byte[] bs = new byte[(int) msg.getBodyLength()];
        String resp = null;
        while (msg.readBytes(bs) != -1) {
            resp = new String(bs, "GBK");

        }
        System.out.println(resp);
        TiripPackage tri = XmlUtil.toBean(resp, TiripPackage.class);
        JhSyYhcxjfTyResBody openResp = XmlUtil.toBean(XmlUtil.subCdata(tri), JhSyYhcxjfTyResBody.class);
        System.out.println(tri);
    }


    /**
     * @throws Exception
     * @createUser daiyuan
     * @createTime 2019/2/27 10:20 AM
     * @describe 个人银行缴费城乡居民查询
     **/

    @Test
    public void gryhJf() throws Exception {


        JhSyYhCxjmcxRqBody open = new JhSyYhCxjmcxRqBody();
        JhSyYhcxjfTyReqHead head = new JhSyYhcxjfTyReqHead("20190305");
        open.setHead(head);

        JhSyYhCxjmcxReqBody jhSyYhCxjmcxReqBody = new JhSyYhCxjmcxReqBody("201", "430111196402120016", "胡迪强", "00000",
                "0000", "1009539960", "");
        open.setBody(jhSyYhCxjmcxReqBody);

        String str = BuilderParam.getJhSyYhCxjmcx(open);
        System.out.println(str);

        String messageId = sendMessage.sendSs(UUID.randomUUID().toString(), str);
        Message message = ssReciveMessage.reciveFromCorrelationID(messageId);
        BytesMessage msg = (BytesMessage) message;
        byte[] bs = new byte[(int) msg.getBodyLength()];
        String resp = null;
        while (msg.readBytes(bs) != -1) {
            resp = new String(bs, "GBK");

        }
        System.out.println(resp);
        TiripPackage tri = XmlUtil.toBean(resp, TiripPackage.class);
        JhSyYhcxjfTyResBody openResp = XmlUtil.toBean(XmlUtil.subCdata(tri), JhSyYhcxjfTyResBody.class);
        System.out.println(tri);

    }


    /**
     * @throws Exception
     * @createUser daiyuan
     * @createTime 2019/2/27 10:20 AM
     * @describe 个人银行缴费灵活就业查询
     **/

    @Test
    public void gryhJfLh() throws Exception {

        JhSyYhLhjycxRqBody open = new JhSyYhLhjycxRqBody();
        JhSyYhLhjycxReqHead head = new JhSyYhLhjycxReqHead("20180619");
        JhSyYhLhjycxReqBody body = new JhSyYhLhjycxReqBody("身份证", "365934659956488895", "张溪阳", "医疗保险", "20180216", "20180719", "001256", "1000.0");

        open.setHead(head);
        open.setBody(body);

        String str = BuilderParam.getJhSyYhLhjycx(open);
        System.out.println(str);

        String messageId = sendMessage.sendSs(UUID.randomUUID().toString(), str);
        Message message = ssReciveMessage.reciveFromCorrelationID(messageId);
        BytesMessage msg = (BytesMessage) message;
        byte[] bs = new byte[(int) msg.getBodyLength()];
        String resp = null;
        while (msg.readBytes(bs) != -1) {
            resp = new String(bs, "GBK");

        }
        System.out.println(resp);
        TiripPackage tri = XmlUtil.toBean(resp, TiripPackage.class);
        JhSyYhLhjycxRpBody openResp = XmlUtil.toBean(XmlUtil.subCdata(tri), JhSyYhLhjycxRpBody.class);
        System.out.println(tri);

    }


    /**
     * @throws Exception
     * @createUser daiyuan
     * @createTime 2019/2/27 10:20 AM
     * @describe 个人银行缴费扣款结果确认
     **/


    @Test
    public void gryhKk() throws Exception {

        JhSyYhKkjgRqBody open = new JhSyYhKkjgRqBody();
        JhSyYhKkjgHead head = new JhSyYhKkjgHead("102100009980", "20180619", "2", "3");

        List<JfmxYhkkjg> jfmxlistYhkkjg = new ArrayList<>();
        JfmxYhkkjg jfmxYhkkjg = new JfmxYhkkjg("1", "2", "3", "4", "5");
        jfmxlistYhkkjg.add(jfmxYhkkjg);
        JhSyYhKkjgReqBody body = new JhSyYhKkjgReqBody("989702368", "23121", jfmxlistYhkkjg);
        open.setHead(head);
        open.setBody(body);

        String str = BuilderParam.getJhSyYhKkjg(open);
        System.out.println(str);

        String messageId = sendMessage.sendSs(UUID.randomUUID().toString(), str);
        Message message = ssReciveMessage.reciveFromCorrelationID(messageId);
        BytesMessage msg = (BytesMessage) message;
        byte[] bs = new byte[(int) msg.getBodyLength()];
        String resp = null;
        while (msg.readBytes(bs) != -1) {
            resp = new String(bs, "GBK");

        }
        System.out.println(resp);
        TiripPackage tri = XmlUtil.toBean(resp, TiripPackage.class);
        JhSyYhKkjgRpBody openResp = XmlUtil.toBean(XmlUtil.subCdata(tri), JhSyYhKkjgRpBody.class);
        System.out.println(tri);

    }

    /**
     * @throws Exception
     * @createUser daiyuan
     * @createTime 2019/2/27 10:20 AM
     * @describe 个人银行缴费撤销
     **/

    @Test
    public void gryhJfCx() throws Exception {

        JhSyYhCxRqBody open = new JhSyYhCxRqBody();
        JhSyYhCxReqHead head = new JhSyYhCxReqHead("102100009980", "20180926");
        JhSyYhCxReqBody body = new JhSyYhCxReqBody("989702368");
        open.setHead(head);
        open.setBody(body);

        String str = BuilderParam.getJhSyYhCx(open);
        System.out.println(str);

        String messageId = sendMessage.sendSs(UUID.randomUUID().toString(), str);
        Message message = ssReciveMessage.reciveFromCorrelationID(messageId);
        BytesMessage msg = (BytesMessage) message;
        byte[] bs = new byte[(int) msg.getBodyLength()];
        String resp = null;
        while (msg.readBytes(bs) != -1) {
            resp = new String(bs, "GBK");

        }
        System.out.println(resp);
        TiripPackage tri = XmlUtil.toBean(resp, TiripPackage.class);
        JhSyYhCxRpBody openResp = XmlUtil.toBean(XmlUtil.subCdata(tri), JhSyYhCxRpBody.class);
        System.out.println(tri);

    }

    /**
     * @throws Exception
     * @createUser daiyuan
     * @createTime 2019/2/27 10:20 AM
     * @describe 个人委托扣款缴费协议（生效/撤销）
     **/

    @Test
    public void grwtKkJf() throws Exception {

        JhSyYhXyRqBody open = new JhSyYhXyRqBody();
        JhSyYhXyReqHead head = new JhSyYhXyReqHead("10274024", "20180915");
        JhSyYhXyReqBody body = new JhSyYhXyReqBody("305626188957286591", "201", "210565338965832950", "张溪阳", "2874063", "00204705", "招商银行", "6217770003490749", "8240652182994");

        open.setHead(head);
        open.setBody(body);

        String str = BuilderParam.getJhSyYhXy(open);
        System.out.println(str);

        String messageId = sendMessage.sendSs(UUID.randomUUID().toString(), str);
        Message message = ssReciveMessage.reciveFromCorrelationID(messageId);
        BytesMessage msg = (BytesMessage) message;
        byte[] bs = new byte[(int) msg.getBodyLength()];
        String resp = null;
        while (msg.readBytes(bs) != -1) {
            resp = new String(bs, "GBK");

        }
        System.out.println(resp);
        TiripPackage tri = XmlUtil.toBean(resp, TiripPackage.class);
        JhSyYhXyRpBody openResp = XmlUtil.toBean(XmlUtil.subCdata(tri), JhSyYhXyRpBody.class);
        System.out.println(tri);

    }

    /**
     * @throws Exception
     * @createUser daiyuan
     * @createTime 2019/2/27 10:20 AM
     * @describe 个人税务实时缴费
     **/

    @Test
    public void grswSsJf() throws Exception {

        JhSySkRqBody open = new JhSySkRqBody();
        JhSySkHead head = new JhSySkHead("10111111101", "105", "20181012", "20181111");
        Jbyhxx jbyhxx = new Jbyhxx("9991", "402100000018", "农商行", "080100002451054", "北京东之丽彩壁纸销售中心");
        Jsyhxx jsyhxx = new Jsyhxx("9991", "402100000018", "农商行", "080100002451054");

        List<SzmxList> szmxlist = new ArrayList<>();
        Szmx szmx1 = new Szmx("201810", "201811", "58290", "税收收入", "307229070", "城市维护建设税", "0087492444858201", "城镇土地使用税", "566.0");
        Szmx szmx2 = new Szmx("201810", "201811", "58290", "税收收入", "307229070", "城市维护建设税", "0087492444858201", "城镇土地使用税", "566.0");
        szmxlist.add(new SzmxList(szmx1));
        szmxlist.add(new SzmxList(szmx2));

        Spmx spmx = new Spmx("131029111111112209", "23986502", "352229196906261016", "北京福宁乐超市", "11502040000", "北京市丰台区国家税务局", "1110105153867", jbyhxx, jsyhxx, "820.0", "20181122", szmxlist);

        JhSySkReqBody body = new JhSySkReqBody(spmx);

        open.setHead(head);
        open.setBody(body);

        String str = BuilderParam.getJhSySk(open);
        System.out.println(str);

        String messageId = sendMessage.sendSs(UUID.randomUUID().toString(), str);
        Message message = ssReciveMessage.reciveFromCorrelationID(messageId);
        BytesMessage msg = (BytesMessage) message;
        byte[] bs = new byte[(int) msg.getBodyLength()];
        String resp = null;
        while (msg.readBytes(bs) != -1) {
            resp = new String(bs, "GBK");

        }
        System.out.println(resp);
        TiripPackage tri = XmlUtil.toBean(resp, TiripPackage.class);
        JhSySkRpBody openResp = XmlUtil.toBean(XmlUtil.subCdata(tri), JhSySkRpBody.class);
        System.out.println(tri);

    }

    /**
     * @throws Exception
     * @createUser daiyuan
     * @createTime 2019/2/27 10:20 AM
     * @describe 个人缴费交易状态查询
     **/


    @Test
    public void grjfJyZtCx() throws Exception {

        JhSySpztcxRqItem open = new JhSySpztcxRqItem();
        JhSyJyztCxHead head = new JhSyJyztCxHead("105", "20181012");
        JhSySpztcxReqItem body = new JhSySpztcxReqItem("SYZTC1", "131029111111112205", "11502040000", "20181012", "23423424", "23422545");

        open.setHead(head);
        open.setBody(body);

        String str = BuilderParam.getJhSySpztcx(open);
        System.out.println(str);

        String messageId = sendMessage.sendSs(UUID.randomUUID().toString(), str);
        Message message = ssReciveMessage.reciveFromCorrelationID(messageId);
        BytesMessage msg = (BytesMessage) message;
        byte[] bs = new byte[(int) msg.getBodyLength()];
        String resp = null;
        while (msg.readBytes(bs) != -1) {
            resp = new String(bs, "GBK");

        }
        System.out.println(resp);
        TiripPackage tri = XmlUtil.toBean(resp, TiripPackage.class);
        JhSySpztcxRpItem openResp = XmlUtil.toBean(XmlUtil.subCdata(tri), JhSySpztcxRpItem.class);
        System.out.println(tri);

    }


    /**
     * @throws Exception
     * @createUser daiyuan
     * @createTime 2019/2/27 10:20 AM
     * @describe 灵活就业人员缴费基数上下限及档次信息查询
     **/


    @Test
    public void lhjyRy() throws Exception {

        JhSyYhLhjySxxAndDcRqBody open = new JhSyYhLhjySxxAndDcRqBody();
        JhSyYhcxjfTyReqHead head = new JhSyYhcxjfTyReqHead("20181226");
        JhSyYhLhjySxxAndDcReqBody body = new JhSyYhLhjySxxAndDcReqBody("111000000000", "10220", "201812");

        open.setHead(head);
        open.setBody(body);

        String str = BuilderParam.getJhSyYhLhjySxxAndDc(open);
        System.out.println(str);

        String messageId = sendMessage.sendSs(UUID.randomUUID().toString(), str);
        Message message = ssReciveMessage.reciveFromCorrelationID(messageId);
        BytesMessage msg = (BytesMessage) message;
        byte[] bs = new byte[(int) msg.getBodyLength()];
        String resp = null;
        while (msg.readBytes(bs) != -1) {
            resp = new String(bs, "GBK");

        }
        System.out.println(resp);
        TiripPackage tri = XmlUtil.toBean(resp, TiripPackage.class);
        JhSyYhLhjySxxAndDcRpBody openResp = XmlUtil.toBean(XmlUtil.subCdata(tri), JhSyYhLhjySxxAndDcRpBody.class);
        System.out.println(tri);

    }

    /**
     * @throws Exception
     * @createUser daiyuan
     * @createTime 2019/2/27 10:20 AM
     * @describe 城乡居民缴费金额上下限及档次信息查询
     **/


    @Test
    public void cxzmJf() throws Exception {

        JhSyYhCxjmSxxAndDcRqBody open = new JhSyYhCxjmSxxAndDcRqBody();
        JhSyYhcxjfTyReqHead head = new JhSyYhcxjfTyReqHead("20181226");
        JhSyYhCxjmSxxAndDcReqBody body = new JhSyYhCxjmSxxAndDcReqBody("111000000000", "10220", "2018");

        open.setHead(head);
        open.setBody(body);

        String str = BuilderParam.getJhSyYhCxjmSxxAndDc(open);
        System.out.println(str);

        String messageId = sendMessage.sendSs(UUID.randomUUID().toString(), str);
        Message message = ssReciveMessage.reciveFromCorrelationID(messageId);
        BytesMessage msg = (BytesMessage) message;
        byte[] bs = new byte[(int) msg.getBodyLength()];
        String resp = null;
        while (msg.readBytes(bs) != -1) {
            resp = new String(bs, "GBK");

        }
        System.out.println(resp);
        TiripPackage tri = XmlUtil.toBean(resp, TiripPackage.class);
        JhSyYhCxjmSxxAndDcRpBody openResp = XmlUtil.toBean(XmlUtil.subCdata(tri), JhSyYhCxjmSxxAndDcRpBody.class);
        System.out.println(tri);
    }
}

